// @Name    : cai_network_monitor
// @author  : simon
// @date    : 2025/5/21 15:14
// @desc    : 网络状态监测
import 'package:connectivity_plus/connectivity_plus.dart';

class CaiNetworkMonitor {
  static final Connectivity _connectivity = Connectivity();

  /// 检查当前网络是否可用
  static Future<bool> isNetworkAvailable() async {
    final result = await _connectivity.checkConnectivity();
    return !result.contains(ConnectivityResult.none);
  }

  /// 获取具体网络类型
  static Future<List<ConnectivityResult>> getNetworkType() async {
    return await _connectivity.checkConnectivity();
  }
}

/*
// 发起请求
Future<void> fetchData() async {
  try {
    final data = await CaiHttpRequest.getRequest('/api/data');
    // 处理数据...
  } on DioException catch (e) {
    if (e.error == 'NETWORK_UNAVAILABLE') {
      showNetworkErrorDialog();
    } else {
      handleOtherErrors(e);
    }
  }
}

// 特殊请求跳过网络检查
Future<void> forceFetch() async {
  final originalSetting = CaiHttpRequest.shared.enableNetworkCheck;
  try {
    CaiHttpRequest.shared.configNetworkCheck(false);
    await CaiHttpRequest.getRequest('/api/important');
  } finally {
    CaiHttpRequest.shared.configNetworkCheck(originalSetting);
  }
}
 */